package com.zkyc.framework.website.config;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zkyc.framework.common.mapper.SystemDictionaryMapper;
import com.zkyc.framework.common.pojo.SystemDictionary;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashSet;

/**
 * @author bing.bai
 * @create 2022/6/16
 */
@Component
public class MathcingConfig {

    public static HashSet<String> completeMatchingSet = new HashSet<String>() {{
    }};

    public static HashSet<String> fuzzyMatchingSet = new HashSet<String>() {{
    }};

    @Autowired
    private SystemDictionaryMapper systemDictionaryMapper;


    @PostConstruct
    public void initMatchingSet() {
        QueryWrapper<SystemDictionary> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dictionary_key", "completeMatching");
        SystemDictionary systemDictionary = systemDictionaryMapper.selectOne(queryWrapper);
        String completeMatching = systemDictionary.getDictionaryValue();
        String[] completeSplit = completeMatching.split(",");
        for (int i = 0; i < completeSplit.length; i++) {
            completeMatchingSet.add(completeSplit[i]);
        }
        QueryWrapper<SystemDictionary> queryWrapper2 = new QueryWrapper<>();
        queryWrapper2.eq("dictionary_key", "fuzzyMatching");
        SystemDictionary fuzzyDictionary = systemDictionaryMapper.selectOne(queryWrapper2);
        String[] fuzzySplit = fuzzyDictionary.getDictionaryValue().split(",");
        for (int i = 0; i < fuzzySplit.length; i++) {
            fuzzyMatchingSet.add(fuzzySplit[i]);
        }
        System.out.println(JSONObject.toJSONString(completeMatching));
        System.out.println(JSONObject.toJSONString(fuzzyMatchingSet));
    }
}
